﻿#ifndef __AVOID_CONTROL_CTLFONTQUEUE_HEAD_FILE_INCLUDED__
#define __AVOID_CONTROL_CTLFONTQUEUE_HEAD_FILE_INCLUDED__
#include "ctlFont.h"
#include <vector>
#include <memory>

namespace swui
{
	class ctlFontQueue
	{
		ctlFontQueue(const ctlFontQueue&);
	public:
		ctlFontQueue();
	public:
		bool setDefaultIndex(unsigned defaultIndex);
		unsigned getDefaultIndex();
	public:
		//添加字体到队列，返回索引
		unsigned addFont(std::shared_ptr<ctlFont>);
		//设置队列的字体
		bool setFont(unsigned index, std::shared_ptr<ctlFont>);
		//获取队列大小
		unsigned getQueueSize();
		//获取队列中的元素
		std::shared_ptr<ctlFont> getElement(unsigned index);
	private:
		std::vector<std::shared_ptr<ctlFont>> _data;
		unsigned _defaultIndex;
	};

	inline std::shared_ptr<ctlFont> ctlFontQueue::getElement(unsigned index)
	{
		return _data[index];
	}
	inline ctlFontQueue::ctlFontQueue() {
		_defaultIndex = addFont(createFont());
	}
	inline bool ctlFontQueue::setDefaultIndex(unsigned defaultIndex) {
		if(getQueueSize() <= defaultIndex) return false;
		_defaultIndex = defaultIndex;
		return true;
	}
	inline unsigned ctlFontQueue::getDefaultIndex() {
		return _defaultIndex;
	}
	inline unsigned ctlFontQueue::addFont(std::shared_ptr<ctlFont> font) {
		font->flush();
		_data.push_back(font);
		return _data.size() - 1;
	}
	inline bool ctlFontQueue::setFont(unsigned index, std::shared_ptr<ctlFont> font) {
		if(getQueueSize() <= index) return false;
		font->flush();
		_data[index] = font;
		return true;
	}
	inline unsigned ctlFontQueue::getQueueSize() {
		return _data.size();
	}
}

#endif